package crazyBook.C6.C6_8;

@FunctionalInterface
interface Displayable {
    //定义一个抽象方法和默认方法
    void display();

    default int add(int a, int b) {
        return a + b;
    }
}

public class LambdaAndInner {
    private int age = 12;
    private static String name = "黄光明";

    public void test() {
        String book = "疯狂Java讲义";
        Displayable dis = () -> {
            //访问"effectively final"的局部变量
            System.out.println("book的局部变量为" + book);
            //访问外部类的实例变量和类变量
            System.out.println("外部类age实例变量为:" + age);
            System.out.println("外部类name类变量为:" + name);

            //Lambda表达式的代码块不允许调用接口中定义的默认方法,
            //如下代码将会报错
            /*System.out.println(add(3,5));*/
        };
        dis.display();
        //调用dis对象从接口中继承的add()方法
        System.out.println(dis.add(3, 5));
    }

    public static void main(String[] args) {
        LambdaAndInner lambda = new LambdaAndInner();
        lambda.test();
    }
}
